package com.lwm.controller;

import com.github.pagehelper.PageInfo;
import com.lwm.domain.FactoryModeling;
import com.lwm.domain.ResponseResult;
import com.lwm.dto.FactoryIdDto;
import com.lwm.dto.FactoryModelingDto;
import com.lwm.service.FactoryModelingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工厂建模控制层
 */
@RestController
@RequestMapping("/factoryModeling")
@Slf4j
public class FactoryModelingController {
    @Resource
    private FactoryModelingService factoryModelingService;

    /**
     * 保存
     *
     * @param factoryModelingDto 工厂建模dto
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping
    public ResponseResult<Object> save(@RequestBody FactoryModelingDto factoryModelingDto) {
        log.info("save factoryModelingDto {}", factoryModelingDto);
        return factoryModelingService.save(factoryModelingDto);
    }

    /**
     * 删除
     *
     * @param factoryIdDto 工厂id dto
     * @return {@link ResponseResult}<{@link Object}>
     */
    @DeleteMapping
    public ResponseResult<Object> remove(@RequestBody FactoryIdDto factoryIdDto) {
        log.info("remove factoryIdDto {}", factoryIdDto);
        return factoryModelingService.remove(factoryIdDto);
    }

    /**
     * 编辑
     *
     * @param factoryModelingDto 工厂建模dto
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PutMapping
    public ResponseResult<Object> edit(@RequestBody FactoryModelingDto factoryModelingDto) {
        log.info("edit factoryModelingDto {}", factoryModelingDto);
        return factoryModelingService.edit(factoryModelingDto);
    }

    /**
     * 分页
     *
     * @param page            页码
     * @param size            数量
     * @param factoryModeling 工厂建模
     * @return {@link ResponseResult}<{@link PageInfo}<{@link FactoryModelingDto}>>
     */
    @GetMapping("/page")
    ResponseResult<PageInfo<FactoryModelingDto>> page(Integer page, Integer size, FactoryModeling factoryModeling) {
        return factoryModelingService.page(page, size, factoryModeling);
    }

    /**
     * 根据id获取
     *
     * @return {@link ResponseResult}<{@link FactoryModelingDto}>
     */
    @GetMapping("/{id}")
    public ResponseResult<FactoryModelingDto> getById(@PathVariable Long id) {
        log.info("id {}", id);
        return factoryModelingService.getById(id);
    }
}
